//
//  ZTTabBar.m
//  项目练习
//
//  Created by 张江涛 on 15/11/30.
//  Copyright © 2015年 张江涛. All rights reserved.
//

#import "ZTTabBar.h"

@interface ZTTabBar ()

/** 发布按钮*/
@property(weak,nonatomic) UIButton *publisdBtn;

@end

@implementation ZTTabBar

/*** 懒加载*/
- (UIButton *)publisdBtn
{
    if (!_publisdBtn) {
        UIButton *publisdBtn = [[UIButton alloc]init];
        
        [publisdBtn setImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        [publisdBtn setImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
        [publisdBtn addTarget:self action:@selector(publisdBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:publisdBtn];
        self.publisdBtn = publisdBtn;
        
    }
    return _publisdBtn;
}


//监听发布按钮
- (void)publisdBtnClick
{
    ZTLongFunc;
}

#pragma mark - 内部的方法
//布局tabBar
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat btnW = self.xmg_width * 0.2;
    CGFloat btnH = self.xmg_height;
    
    self.publisdBtn.xmg_height = btnH;
    self.publisdBtn.xmg_width = btnW;
    self.publisdBtn.center = CGPointMake(self.xmg_width * 0.5 ,self.xmg_height * 0.5 );
    
    //定义tabBarButton的索引
    int tabBarIndex = 0 ;
    
    for (UIView *tabBarBtn in self.subviews) {
        
        if (![@"UITabBarButton" isEqualToString:NSStringFromClass(tabBarBtn.class)]) continue;
        
        tabBarBtn.xmg_height = btnH;
        tabBarBtn.xmg_width  = btnW;
        tabBarBtn.xmg_x = btnW * tabBarIndex;
        tabBarBtn.xmg_y = 0;
        
        //给发布按钮空出位置
        if (tabBarIndex >= 2) {
            tabBarBtn.xmg_x += btnW;
        }
        //增加索引
        tabBarIndex ++ ;
        
    }
    
}


@end
